package com.sx.pipeline.adapter

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.hjq.widget.layout.CircleImageView
import com.sx.pipeline.R
import com.sx.pipeline.repos.http.res.GroupBean
import com.sx.pipeline.utils.GlideEngine

class GroupManagerAdapter(val maxCount: Int?=null) : BaseMultiItemQuickAdapter<GroupBean, BaseViewHolder>(
) {
    init {
        addItemType(0, R.layout.item_group_manager)
        addItemType(1, R.layout.item_group_option)
        addItemType(2, R.layout.item_group_option)
    }

    override fun convert(holder: BaseViewHolder, item: GroupBean) {
        if(item.itemType==0){
            GlideEngine.createGlideEngine().loadImage(
                context, item.contact?.avatar.orEmpty(), holder.getView<ImageView>(R.id.iv_head)
            )
            holder.setText(R.id.tv_name,item.contact?.userName.orEmpty())
            if(item.contact?.userType==1){
                holder.setText(R.id.tv_admin,"群主")
                holder.getView<TextView>(R.id.tv_admin).visibility= View.VISIBLE
            }else if(item.contact?.userType==2){
                holder.setText(R.id.tv_admin,"管理员")
                holder.getView<TextView>(R.id.tv_admin).visibility= View.VISIBLE
            }else{
                holder.getView<TextView>(R.id.tv_admin).visibility= View.GONE
            }
        }else if(item.itemType==1){
            holder.setImageResource(R.id.iv_option,R.mipmap.ic_add)
        }else if(item.itemType==2){
            holder.setImageResource(R.id.iv_option,R.mipmap.ic_minus)
        }
    }

    override fun getItemCount(): Int {
        val itemCount = super.getItemCount()
        if(maxCount==null){
            return itemCount
        }else{
            if(itemCount>maxCount){
                return maxCount
            }else{
                return itemCount
            }
        }

    }
}